import { useEffect, useState } from "react"
import request  from "../utils/request"
import {Timeline,Button} from "antd"
function Dashboard() {
  const [blogList,setBlogList] = useState([])

  useEffect(()=>{
     request.get("/user/getMasterSelfBlog",{
      params:{
         pageNum:1,
         pageSize:5
      }
     }).then(res=>{
      console.log(res)
      let filterbloglist = res.data.data.filter(item=>{
        return item.publish===1
     })
     setBlogList(filterbloglist)
     })
  },[])
  function clickfn(){
     request.post('/user/uploadBlogImage',{
        blogId:'eb6101c0-0669-11ee-baa5-2b0852bc3be5',
        imagePath:'https://picsum.photos/200/300?random=1'
     }).then(res=>{
      console.log(res)
     })
  }
  const delfn = ()=>{
     request.post('/user/updateBlogStatus',{
       blogId:'eb6101c0-0669-11ee-baa5-2b0852bc3be5',
       status:0
     }).then(res=>{
      console.log(res)
     })
  }
  return (
    <div>
      <h1>看板页</h1>
      <Timeline>
         {
         
          blogList?.map(item=>(
             <Timeline.Item key={item.id}>
                {item.title}/{item.author}/{item.create_time}/{item.title}
                 <br/>
                 <img src={item.picture} alt={item.title} style={{width:'200px'}}/>
             </Timeline.Item>
          ))
         }  
      </Timeline> 
      <Button onClick={clickfn}>上传博客封面</Button>
      <Button onClick={delfn}>下架博客</Button>
    </div>
  )
}
export default Dashboard